<?php
namespace Realisation;

use Doctrine\DBAL\Connection;
use Model\Entity\Url;

/**
 * Description of UrlProvider
 *
 * @author pahhan
 */
class UrlProvider
{
    /**
     *
     * @var Connection
     */
    private $conn;

    function __construct(Connection $conn) {
        $this->conn = $conn;
    }

    public function getUrl($id)
    {
        $url_arr = $this->conn->fetchAssoc('SELECT * FROM url WHERE id = ?', array($id));
        if( empty($url_arr) ) {
            throw new \RuntimeException(sprintf('Url with id = %s not found', $id));
        }

        $url = new Url();

        $url->setId($id);
        $url->setCharset($url_arr['charset']);
        $url->setSiteId($url_arr['site_id']);
        $url->setUrl($url_arr['url']);
        $url->setKey($url_arr['key']);
        $url->setDescription($url_arr['description']);

        return $url;
    }
}

